#include "Aluno.h"

Aluno::Aluno(int x, int y, string fileName) : GameObject(x, y, fileName)
{
    vx = 0;
    vy = 0;
    this->x = x;
    path = true;
    direction = 0;
    this->y = y;
    for(int i = 1; i < 9; i++)
        corner[i] = false;
    corner[0] = true;
    life = 10;
}

int Aluno::Update(int dt)
{
    SDL_Rect rec = animation[direction]->GetRect();

    vx = -dt/10;
    vy = dt/10;

    if(corner[0])
    {
        direction = 0;
        y = y +vy;
        //desce
    }
    else if(corner[1])
    {
        direction = 3;
        x = x + vx;
        //esquerda
    }
    else if(corner[2])
    {
        direction = 0;
        y = y + vy;
        //desce
    }
    else if(corner[3])
    {
        direction = 3;
        x = x + vx;
        //esquerda
    }
    else if(corner[4])
    {
        direction = 0;
        y = y + vy;
        //desce
    }
    else if(corner[5])
    {
        direction = 3;
        x = x + vx;
        //esquerda
    }
    else if(corner[6])
    {
        if(path)
        {
            direction = 0;
            y = y + vy;
            //desce
        }
        else
        {
            direction = 3;
            x = x + vx;
            //esquerda
        }
    }
    else if(corner[7])
    {
        if(path)
        {
            direction = 3;
            x = x + vx;
            //esquerda
        }
        else
        {
            direction = 0;
            y = y + vy;
            //desce
        }
    }
    else if(corner[8])
        if(path)
        {
            direction = 0;
            y = y+ vy;
        }

    if((y > 203) && (x == 731))
    {
        corner[0] = false;
        corner[1] = true;
    }
    else if((y > 203) && (y < 251) && (x <= 539))
    {
        corner[1] = false;
        corner[2] = true;
    }
    else if((y >= 251) && (x <= 539) && (x > 299))
    {
        corner[2] = false;
        corner[3] = true;
    }
    else if((y >= 251) && (y < 491) && (x <= 299))
    {
        corner[3] = false;
        corner[4] = true;
    }
    else if((y >= 491) && (x <= 299) && (x > 203))
    {
        corner[4] = false;
        corner[5] = true;
    }
    else if((y >= 491) && (y < 683) && (x <= 203) && (x > 11))
    {
        corner[5] = false;
        corner[6] = true;
    }
    else if((y >= 730) && (x <= 203) && (x > 11))
    {
        corner[6] = false;
        corner[7] = true;
    }
    else if((y >= 491) && (y < 683) && (x <= 11))
    {
        corner[6] = false;
        corner[7] = true;
    }
    else if((y >= 730) && (x <= 11))
    {
        corner[7] = false;
        corner[8] = true;
    }

    return 0;
}
